/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mycompany.psc.beans;

import com.mycompany.psc.entities.Users;
import com.mycompany.psc.producers.LoggedIn;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.push.PushContext;
import org.primefaces.push.PushContextFactory;

/**
 *
 * @author A7med
 */
@Named
@SessionScoped
public class ChatBean implements Serializable{
    private List<String> shoutList=new ArrayList<>();
    private String shout;
    @Inject
    @LoggedIn
    Users current;

    public String getShout() {
        return shout;
    }

    public void setShout(String shout) {
        this.shout = shout;
    }

    /**
     * @return the shoutList
     */
    public List<String> getShoutList() {
        return shoutList;
    }

    /**
     * @param shoutList the shoutList to set
     */
    public void setShoutList(List<String> shoutList) {
        this.shoutList = shoutList;
    }
    public void addshout(String shout){
        shoutList.add(shout);
    }
     public void send() {
        PushContext pushContext = PushContextFactory.getDefault().getPushContext();
        String content="<div class='chatLine'><div class='userName'>"+current.getName()+": </div><div class='shout'>"+shout+"</div></div>";
         System.out.println("content="+content);
        pushContext.push("/notifications", content);
    }
}
